class Solution {
public:
    int findMaxForm(vector<string>& strs, int m, int n)
    {
        int sz = strs.size();
        vector dp(sz + 1, vector(m + 1, vector<int>(n + 1, 0)));
        for (int i = 1; i <= sz; i++)
        {
            for (int j = 0; j <= m; j++)
            {
                for (int k = 0; k <= n; k++)
                {
                    dp[i][j][k] = dp[i - 1][j][k];
                    int cnt0 = count(strs[i - 1].begin(), strs[i - 1].end(), '0');
                    int cnt1 = strs[i - 1].size() - cnt0;
                    if (j >= cnt0 && k >= cnt1)
                        dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - cnt0][k - cnt1] + 1);
                }
            }
        }
        return dp[sz][m][n];
    }
};